﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using mbhxnaengine.Code.GameObject;
using mbhxnaengine.Code.Game;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace mbhxnaengine.Code.Utilities
{
    class FrameRate : GameObject.GameObject
    {
        int frameRate = 0;
        int frameCounter = 0;
        TimeSpan elapsedTime = TimeSpan.Zero;

        // Called once, when the object is loaded.
        //
        public override void LoadContent(String fileName)
        {
        }

        // Called every frame.
        //
        public override void Update(GameTime gameTime)
        {
            elapsedTime += gameTime.ElapsedGameTime;

            if (elapsedTime > TimeSpan.FromSeconds(1))
            {
                elapsedTime -= TimeSpan.FromSeconds(1);
                frameRate = frameCounter;
                frameCounter = 0;
            }
        }

        // Called at the end of every frame.
        //
        public override void Render(SpriteBatch batch)
        {
            frameCounter++;

            string fps = string.Format("FPS: {0}", frameRate);

            DebugMessageDisplay.pInstance.AddDynamicMessage(fps);
        }
    }
}
